package com.xinke.module.system.mapper.tenant;

import java.util.*;

import com.xinke.component.common.pojo.PageResult;
import com.xinke.component.mybatis.mybatis.core.query.LambdaQueryWrapperExt;
import com.xinke.component.mybatis.mybatis.core.mapper.BaseMapperExt;
import com.xinke.module.system.model.entity.tenant.TenantDO;
import org.apache.ibatis.annotations.Mapper;
import com.xinke.module.system.model.vo.tenant.*;

/**
 * 租户 Mapper
 *
 * @author yzx
 */
@Mapper
public interface TenantMapper extends BaseMapperExt<TenantDO> {

    default PageResult<TenantDO> selectPage(TenantPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperExt<TenantDO>()
                .likeIfPresent(TenantDO::getTenantName, reqVO.getTenantName())
                .eqIfPresent(TenantDO::getContactUserId, reqVO.getContactUserId())
                .likeIfPresent(TenantDO::getContactName, reqVO.getContactName())
                .eqIfPresent(TenantDO::getContactPhone, reqVO.getContactPhone())
                .eqIfPresent(TenantDO::getTenantStatus, reqVO.getTenantStatus())
                .eqIfPresent(TenantDO::getBindWebsite, reqVO.getBindWebsite())
                .eqIfPresent(TenantDO::getPackageId, reqVO.getPackageId())
                .betweenIfPresent(TenantDO::getExpireTime, reqVO.getExpireTime())
                .eqIfPresent(TenantDO::getAccountCount, reqVO.getAccountCount())
                .orderByDesc(TenantDO::getTenantId));
    }

    default TenantDO selectByName(String name) {
        return selectOne(TenantDO::getTenantName, name);
    }
}